package com.qian.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qian.mapper.EmployeeMapper;
import com.qian.pojo.Employees;
import com.qian.utils.SnowFlake;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeService extends ServiceImpl<EmployeeMapper, Employees> {

    @Resource
    private EmployeeMapper employeeMapper;

    //查询本租户内的所有员工
    public List<Employees> searchAllEmployee() {
        return employeeMapper.selectList(null);
    }

    //通过id查询本租户内的相应员工
    public Employees searchEmployeeById(Long employeeId) {
        return employeeMapper.selectById(employeeId);
    }

    //通过帐号查询本租户内的员工
    public List<Employees> searchEmployeeByAccount(String employeeAccount) {
        Map map = new HashMap();
        map.put("employee_account", employeeAccount);
        return employeeMapper.selectByMap(map);
    }

    //登录查询
    public List<Employees> employeeLogin(String employeeAccount) {
        return employeeMapper.employeeLogin(employeeAccount);
    }

    //更新本租户内的员工
    public void updateEmployee(Employees employees) {
        employeeMapper.updateById(employees);
    }

    //增加本租户内的员工
    public void addEmployee(Employees employees) {
        employeeMapper.insert(employees);
    }

    //查询所有租户
    public List<Employees> tenantAll(int authority, String employeeName) {
        return employeeMapper.tenantAll(authority, employeeName);
    }

    //增加租户
    public void addTenant(Employees employees) {
        employees.setEmployeeId(SnowFlake.nextId());
        employeeMapper.addTenant(employees);
    }

    //获取当前的租户最大值,为新增租户工具
    public int maxTenant() {
        return employeeMapper.maxTenant();
    }

    //根据id查询租户信息
    public Employees queryTenantById(Long employeeId) {
        return employeeMapper.queryTenantById(employeeId);
    }

    //更新租户信息
    public void updateTenant(Employees employees) {
        employeeMapper.updateTenant(employees);
    }

    //删除租户信息
    public void deleteTenant(Long employeeId) {
        employeeMapper.deleteTenant(employeeId);
    }

    //查询所有的租户号
    public List<Long> allTenants(){
        return employeeMapper.allTenants();
    }
}
